package com.hotel.hotelsystem.controller;



import com.baomidou.mybatisplus.extension.api.ApiController;
import com.common.status.ResultMsg;
import com.common.status.StatusCode;
import com.common.utils.ResultUtils;
import com.common.utils.ResultVo;
import com.hotel.hotelsystem.pojo.HotelInfo;
import com.hotel.hotelsystem.pojo.RoomInfo;
import com.hotel.hotelsystem.pojo.RoomList;
import com.hotel.hotelsystem.pojo.TenantList;
import com.hotel.hotelsystem.service.RoomInfoService;
import com.hotel.hotelsystem.service.RoomListService;
import com.hotel.hotelsystem.service.RoomService;
import com.hotel.hotelsystem.service.TenantListService;
import com.hotel.ordersystem.pojo.CommentMongoDB;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * (RoomList)表控制层
 *
 * @author makejava
 * @since 2022-09-30 18:23:54
 */
@Api(value = "RoomListController",tags = {"房间信息模块"})
@RestController
@RequestMapping("room")
public class RoomListController{
    /**
     * 服务对象
     */
    @Resource
    private RoomListService roomListService; // 房间列表
    @Resource
    private RoomInfoService roomInfoService; // 房间信息
    @Resource
    private TenantListService tenantListService; // 入住信息
    @Resource
    private RoomService roomService; // 房间信息


    @GetMapping("saveRedis")
    public void roomListSaveRedis(){

    }

    @GetMapping("/getRoomListByRoomTypeId/{roomTypeId}/{num}")
    public RoomList getRoomListByRoomTypeId(@PathVariable("roomTypeId") String roomTypeId,@PathVariable("num") String num){
        System.out.println("获取对象: "+roomTypeId+"==>"+num);
        return roomListService.getById(roomTypeId,num);
    }

    @ApiOperation(value = "根据酒店号查询房间信息")
    @GetMapping("/getRooms/{id}")
    public List<RoomList> getRooms(@PathVariable("id") int id){
        return roomListService.selectHotelToRoomList(id);
    }

    @ApiOperation(value = "根据前端日期查询剩余房间数量")
    @GetMapping("/getRooms/{startTime}/{endTime}/{hotelId}")
    public Map<Integer,Integer> getNumOfRooms(@PathVariable("startTime") String startTimeStr,
                                              @PathVariable("endTime") String endTimeStr,
                                              @PathVariable("hotelId") int hotelId){
        //对前端获取的日期字符串进行处理
        System.out.println("正在执行中...................................");
        String[] split1 = startTimeStr.split("-");
        String[] split2 = endTimeStr.split("-");
        LocalDateTime startTime = LocalDateTime.of(Integer.valueOf(split1[0]), Integer.valueOf(split1[1]), Integer.valueOf(split1[2]), 0, 0, 0);
        LocalDateTime endTime = LocalDateTime.of(Integer.valueOf(split2[0]), Integer.valueOf(split2[1]), Integer.valueOf(split2[2]), 0, 0, 0);
        return roomService.getAllTypeRoomNumByTime(hotelId,startTime,endTime);
    }

    @ApiOperation(value = "入住人表")
    @GetMapping("/getTenantList")
    public ResultVo<List<TenantList>> getTenantList() {
        List<TenantList> list = tenantListService.list();
        if (list.size() != 0) return ResultUtils.success(ResultMsg.SUCCESS_MSG, StatusCode.SUCCESS_CODE,list);
        else return ResultUtils.error(ResultMsg.DATA_NULL, StatusCode.SYSTEM_ERROR_CODE,null);
    }

    /**
     * 根据酒店id查看评论信息
     * @param hotelId
     */
    @GetMapping("/getCommentByHotelId/{hotelId}")
    public ResultVo<List<CommentMongoDB>> getCommentByHotelId(@PathVariable("hotelId") String hotelId){
        return roomListService.getCommentByHotelId(hotelId);
    }

}

